<?php

namespace App\Http\Controllers\Wechat;

use App\Models\WechatUser;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class WechatUserController extends Controller
{
    public function index(Request $request)
    {
        $query = WechatUser::query();

        if ($search = $request->input('search')) {
            $query->where(function($q) use ($search) {
                $q->where('id', 'like', $search)
                  ->orWhere('nickname', 'like', "%{$search}%");
            });
        }

        $wechatUsers = $query->latest()
                            ->paginate(15)
                            ->withQueryString();

        return view('wechat.users.index', compact('wechatUsers'));
    }
} 